package org.hcyspartnoc.luoxin.pojo.po.searchtopic;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.hcyspartnoc.luoxin.pojo.dto.searchtopic.QuestionUpdateDto;
import org.hcyspartnoc.luoxin.pojo.vo.searchtopic.QuestionVo;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class QuestionPo implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    private Integer id;
    private Integer bankId;
    private String queTopic;
    private String queAnswer;
    private String queAnalysis;
    private String aiAnalysis;
    private Long queType;
    private List<QuestionOptions> options = new ArrayList<>();  // 初始化选项列表





    @Data
    @NoArgsConstructor
    public static class QuestionOptions {  // 改为静态类以便外部访问
        private Integer queId;
        private String option;
        private Integer id;

        // 构造函数用于直接创建选项
        public QuestionOptions(String option) {
            this.option = option;
        }
        public QuestionOptions(Integer queId) {
            this.queId = queId;
        }

        public QuestionOptions(Integer id, String option) {
            this.id = id;
            this.option = option;
        }
    }
    public void setOptionsByUpdateDto(QuestionUpdateDto questionUpdateDto) {
        for (QuestionUpdateDto.QuestionOptions questionOptionPo : questionUpdateDto.getOptions()) {
            QuestionOptions option = new QuestionOptions(
                    questionOptionPo.getId(),
                    questionOptionPo.getOption()
            );
            this.options.add(option);
        }
    }
    // 方法用于添加选项
    public void addOption(String option) {
        this.options.add(new QuestionOptions(option));
    }
    // 设置所有选项的 queId，作为关联问题的主键
    public void setOptionsQueId(Integer queId) {
        for (QuestionOptions option : this.options) {
            option.setQueId(queId);  // 为每个选项设置问题主键ID
        }
    }
}
